package com.gitee.lichoking.mysoap.convert;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 加载转换器
 *
 * @author lich
 * @date 2021/6/1
 */
public class DefaultConverterLoader {
    private static Map<Class<?>, Converter<?>> allConverter;

    static {
        allConverter = new HashMap<>(16);
        allConverter.put(BigInteger.class, new BigInterConverter());
        allConverter.put(BigDecimal.class, new BigDecimalConverter());
        allConverter.put(Boolean.class, new BooleanConverter());
        allConverter.put(Byte.class, new ByteConverter());
        allConverter.put(Date.class, new DateConverter());
        allConverter.put(Double.class, new DoubleConverter());
        allConverter.put(Float.class, new FloatConverter());
        allConverter.put(Integer.class, new IntegerConverter());
        allConverter.put(Long.class, new LongConverter());
        allConverter.put(Short.class, new ShortConverter());
        allConverter.put(String.class, new StringConverter());
    }

    public static Converter<?> loadConverter(Class<?> type) {
        return allConverter.get(type);
    }

    public static boolean hasConverter(Class<?> type) {
        return allConverter.get(type) == null ? false : true;
    }

    public static Map<Class<?>, Converter<?>> getAllConverter() {
        return allConverter;
    }

    public static void putConverter(Class<?> type, Converter<?> converter) {
        allConverter.put(type, converter);
    }
}
